<?php
define('KE', 1);
define('IN_SCRIPT', 1);
define('HESK_PATH', '../');
define('HESK_NO_ROBOTS', 1);

/* Get all the required files and functions */
require(HESK_PATH . 'hesk_settings.inc.php');
require(HESK_PATH . 'inc/common.inc.php');
require(HESK_PATH . 'inc/database.inc.php');

hesk_session_start();
hesk_dbConnect();

if (!$_SESSION['isadmin']) {
    exit();
}

/* Print header */
require_once(HESK_PATH . 'inc/header.admin.inc.php');

/* Print admin navigation */
require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');

if (isset($_POST['submit'])) {
    $cat_name = $_POST['category'];
    hesk_dbQuery("INSERT INTO hesk_diag_parent_cat(id, name) VALUES (NULL, '$cat_name')");
}

if (isset($_GET['action'])) {
    $action = $_GET['action'];
    $id = $_GET['id'];

    if ($action == "delete") {
        hesk_dbQuery("DELETE FROM hesk_diag_parent_cat WHERE `id` = $id;");
    }
}

$result = hesk_dbQuery("SELECT * FROM hesk_diag_parent_cat;");
?>
<br />
<table width="100%" border="1" cellspacing="0" cellpadding="3">
    <tr>
        <th>Category</th>
        <th>Action</th>
    </tr>

    <?php
    while ($row = hesk_dbFetchAssoc($result)) {
        ?>
        <tr>
            <td><?php echo $row['name']; ?></td>
            <td><a href="ce_edit.php?id=<?php echo $row['id']; ?>">Edit</a> <a href="ce.php?action=delete&id=<?php echo $row['id']; ?>">Hapus</a></td>
        </tr>
        <?php
    }
    ?>

</table>
<br />
<form name="cat_form" action="ce.php" method="post">
    Tambah ketegori baru: <input type="text" name="category" />
    <input type="submit" name="submit" value="Save" />
</form>
<a href="te.php"><p>Kembali</p></a>
<?php
hesk_dbClose();
require_once(HESK_PATH . 'inc/footer.inc.php');
?>
